#Twisted Shootout
#Copyright (C) 2007 Han Dao
#
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

#You can contact the author at wikipediankiba@gmail.com
import pygame
import data
import mapedit
import menuoptions
import menucollide
import createmenu
import loadmenu
pygame.init()
display = pygame.display.set_mode((1024,768))
pygame.display.set_caption("TS Mapmaker")
class EditMenu:
	def __init__(self):
		self.data = data.read
		self.options = menuoptions.MenuOptions()
		self.options.activate()
		self.collide = menucollide.MenuCollide(self.options)
		self.create = createmenu.CreateMenu()
		self.load = loadmenu.LoadMenu()
	def run(self):
		background = self.data.load("mapmaker",True)
		display.blit(background,[0,0])
		while 1:
			pygame.display.flip()
			for k in pygame.event.get():
				if k.type == pygame.QUIT:
					return
				if k.type == pygame.KEYDOWN:
					if k.key == pygame.K_ESCAPE:
						return
				if k.type == pygame.MOUSEBUTTONDOWN:
					pos = pygame.mouse.get_pos()
					key = pygame.Rect(pos[0],pos[1],1,1)
					self.effect(key)
			self.draw()
	def effect(self,key):
		a = self.collide.menu(key)
		if a == 1:
			self.load.run(display)
			self.edit = mapedit.MapEdit(self.load.options.name)
			self.edit.run(display)
		elif a == 2:
			self.create.run(display)
	def draw(self):
		self.options.sprites.draw(display)